(function () {
    var data = $("#post-form").serializeArray();
    $.ajax({
        url: "/system/mTelRcd/accSubjectDraw",
        data: data,
        type: "POST",
        dataType: "json",
        beforeSend: function () {
            $('#loading').modal('show');
        },
        complete: function () {
            $('#loading').modal('hide');
        },
        success: function (data) {
            // data = jQuery.parseJSON(data);  //dataType指明了返回数据为json类型，故不需要再反序列化
            var contentObj = document.getElementsByClassName("content")[0];
            if(data.rows.length==0){
                contentObj.innerHTML = '没有数据';
                $('#expandBtn').parent().hide();
            }else {
                var isHtml = "";
                var arr = data.rows;

                for (var i = 0; i < data.rows.length; i++) {
                    let wkFmNo = arr[i].wkFmNo == null ? '暂无' : arr[i].wkFmNo;
                          // console.log(arr[i])
                    isHtml += '<div class="col-sm-12 work-box" ondblclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')">';
                    isHtml += '<div class="work-box-top">';
                    isHtml += '<div class="col-sm-12 work-box-top-box">';
                    isHtml += '<div class="col-sm-10"><a class="work-box-a" onclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')"><span>'+arr[i].fromName+'[' + arr[i].dfmClaName +']'+arr[i].dcntAname+'</span></a></div>';
                    isHtml += '<div class="col-sm-2">';
                    isHtml += '<button type="button" class="btn btn-sm btn-primary" onclick="copy('+'\''+arr[i].pkId+'\''+')" style="color: #206ef7;background-color: white;margin-right: 15px;">一键复制';
                    isHtml += '</button>';
                    // isHtml += '<i class="fa fa-chevron-circle-right"></i>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                    isHtml += '<div class="col-sm-12 work-box-top-class" onclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')">'
                    isHtml += '<div class="col-sm-6"><a style="color: inherit">流水号：'+arr[i].wsCode+'</a></div>'
                    isHtml += '<div class="col-sm-6"><a style="color: inherit">工单编号：'+wkFmNo +'</a></div>'
                    isHtml += '</div>'
                    isHtml += '<div class="col-sm-12 work-box-class" onclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')">';
                    isHtml += '<a style="color: inherit">'+ arr[i].fmContent + '</a>'
                    isHtml += '</div>'
                    isHtml += '<div class="col-sm-12 work-box-buttom">';
                    isHtml += '<div class="col-sm-6">' + arr[i].fromTime + '</div>';
                    isHtml += '<div class="col-sm-4">';
                    isHtml += '<div class="col-sm-12 entering-pd">处理情况：'+arr[i].stateDesc+'</div>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                };
                // 一页有多少条数据
                var size = 5;
                // 当前页码
                var curPage = 1;
                // 总共有多少页
                var totalPage = Math.floor((data.total / size) + 1);
                // 是否有下一页
                var hasNext = curPage != totalPage;
                if(hasNext){
                    isHtml += '<div id="txtMore'+curPage+'" style="text-align: center" onclick="more('+totalPage+','+size+','+(curPage+1)+')"><a>更多</a></div>'
                }else{
                    isHtml += '<div style="text-align: center">没有更多了......</div>'
                }
                contentObj.innerHTML = isHtml;
            }

        }

    });


    copy=function(val) {
        $.ajax({
            cache: true,
            type: "POST",
            url:  "/system/mTelRcd/copy",
            data: {
                id: val
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                parent.window[parent.length-2].copy(0,data);
            }
        });
    }

    more = function(totalPage,size,curPage) {
        $('#txtMore'+(curPage - 1)).fadeOut('fast',function(){
            data.push({name: "pageSize", value: size});
            data.push({name: "pageNum", value: curPage});
            $.ajax({
                url: "/system/mTelRcd/accSubjectDraw",
                data: data,
                type: "POST",
                dataType: "json",
                success: function (data) {
                    // data = jQuery.parseJSON(data);  //dataType指明了返回数据为json类型，故不需要再反序列化
                    var contentObj = document.getElementsByClassName("content")[0];
                    var isHtml = contentObj.innerHTML;
                    var arr = data.rows;

                    var hasNext = totalPage != curPage;

                    for (var i = 0; i < data.rows.length; i++) {
                        let wkFmNo = arr[i].wkFmNo == null ? '暂无' : arr[i].wkFmNo;
                        // console.log(arr[i])
                        isHtml += '<div class="col-sm-12 work-box" ondblclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')">';
                        isHtml += '<div class="work-box-top">';
                        isHtml += '<div class="col-sm-12 work-box-top-box">';
                        isHtml += '<div class="col-sm-10"><a class="work-box-a" onclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')"><span>'+arr[i].fromName+'[' + arr[i].dfmClaName +']'+arr[i].dcntAname+'</span></a></div>';
                        isHtml += '<div class="col-sm-2">';
                        isHtml += '<button type="button" class="btn btn-sm btn-primary" onclick="copy(0,'+'\''+arr[i].pkId+'\''+')" style="color: #206ef7;background-color: white;margin-right: 15px;">一键复制';
                        isHtml += '</button>';
                        // isHtml += '<i class="fa fa-chevron-circle-right"></i>';
                        isHtml += '</div>';
                        isHtml += '</div>';
                        isHtml += '<div class="col-sm-12 work-box-top-class" onclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')">'
                        isHtml += '<div class="col-sm-6"><a style="color: inherit">流水号：'+arr[i].wsCode+'</a></div>'
                        isHtml += '<div class="col-sm-6"><a style="color: inherit">工单编号：'+wkFmNo +'</a></div>'
                        isHtml += '</div>'
                        isHtml += '<div class="col-sm-12 work-box-class" onclick="parent.telDetail('+arr[i].wkPkId+','+arr[i].pkId+')">';
                        isHtml += '<a style="color: inherit">'+ arr[i].fmContent + '</a>'
                        isHtml += '</div>'
                        isHtml += '<div class="col-sm-12 work-box-buttom">';
                        isHtml += '<div class="col-sm-6">' + arr[i].fromTime + '</div>';
                        isHtml += '<div class="col-sm-4">';
                        isHtml += '<div class="col-sm-12 entering-pd">处理情况：'+arr[i].stateDesc+'</div>';
                        isHtml += '</div>';
                        isHtml += '</div>';
                        isHtml += '</div>';
                        isHtml += '</div>';
                    };
                    if(hasNext){
                        isHtml += '<div id="txtMore'+curPage+'" style="text-align: center" onclick="more('+totalPage+','+size+','+(curPage+1)+')"><a>更多</a></div>'
                    }else{
                        isHtml += '<div style="text-align: center">没有更多了......</div>'
                    }
                    contentObj.innerHTML = isHtml;

                }

            });
        });
    }


})();

